from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-22 14:05:00.146551
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 22, Oct, 2022
Time: 14:05:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7881
Nobs: 817.000 HQIC: -51.1076
Log likelihood: 10615.3 FPE: 5.22239e-23
AIC: -51.3065 Det(Omega_mle): 4.68078e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.292992 0.052116 5.622 0.000
L1.Burgenland 0.108677 0.035221 3.086 0.002
L1.Kärnten -0.106499 0.018762 -5.676 0.000
L1.Niederösterreich 0.210559 0.073702 2.857 0.004
L1.Oberösterreich 0.101750 0.070669 1.440 0.150
L1.Salzburg 0.250295 0.037487 6.677 0.000
L1.Steiermark 0.037898 0.049123 0.771 0.440
L1.Tirol 0.106500 0.039836 2.673 0.008
L1.Vorarlberg -0.058537 0.034259 -1.709 0.088
L1.Wien 0.060743 0.063016 0.964 0.335
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063193 0.107819 0.586 0.558
L1.Burgenland -0.033033 0.072867 -0.453 0.650
L1.Kärnten 0.047790 0.038815 1.231 0.218
L1.Niederösterreich -0.172906 0.152476 -1.134 0.257
L1.Oberösterreich 0.385586 0.146201 2.637 0.008
L1.Salzburg 0.286297 0.077554 3.692 0.000
L1.Steiermark 0.105344 0.101627 1.037 0.300
L1.Tirol 0.313892 0.082415 3.809 0.000
L1.Vorarlberg 0.025403 0.070877 0.358 0.720
L1.Wien -0.014995 0.130370 -0.115 0.908
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188507 0.026747 7.048 0.000
L1.Burgenland 0.090497 0.018076 5.006 0.000
L1.Kärnten -0.008459 0.009629 -0.879 0.380
L1.Niederösterreich 0.264520 0.037825 6.993 0.000
L1.Oberösterreich 0.126133 0.036268 3.478 0.001
L1.Salzburg 0.048580 0.019239 2.525 0.012
L1.Steiermark 0.017341 0.025211 0.688 0.492
L1.Tirol 0.094820 0.020445 4.638 0.000
L1.Vorarlberg 0.059252 0.017583 3.370 0.001
L1.Wien 0.119776 0.032341 3.704 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107983 0.027416 3.939 0.000
L1.Burgenland 0.044734 0.018528 2.414 0.016
L1.Kärnten -0.016166 0.009870 -1.638 0.101
L1.Niederösterreich 0.193014 0.038771 4.978 0.000
L1.Oberösterreich 0.293694 0.037175 7.900 0.000
L1.Salzburg 0.116068 0.019720 5.886 0.000
L1.Steiermark 0.099850 0.025841 3.864 0.000
L1.Tirol 0.116920 0.020956 5.579 0.000
L1.Vorarlberg 0.070682 0.018022 3.922 0.000
L1.Wien -0.027280 0.033150 -0.823 0.411
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122135 0.049820 2.452 0.014
L1.Burgenland -0.050849 0.033669 -1.510 0.131
L1.Kärnten -0.040538 0.017935 -2.260 0.024
L1.Niederösterreich 0.169613 0.070454 2.407 0.016
L1.Oberösterreich 0.138375 0.067554 2.048 0.041
L1.Salzburg 0.285848 0.035835 7.977 0.000
L1.Steiermark 0.033588 0.046958 0.715 0.474
L1.Tirol 0.166193 0.038081 4.364 0.000
L1.Vorarlberg 0.104629 0.032750 3.195 0.001
L1.Wien 0.072864 0.060239 1.210 0.226
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059065 0.039422 1.498 0.134
L1.Burgenland 0.039432 0.026642 1.480 0.139
L1.Kärnten 0.050738 0.014192 3.575 0.000
L1.Niederösterreich 0.225418 0.055750 4.043 0.000
L1.Oberösterreich 0.282245 0.053455 5.280 0.000
L1.Salzburg 0.051725 0.028356 1.824 0.068
L1.Steiermark -0.007776 0.037158 -0.209 0.834
L1.Tirol 0.149942 0.030133 4.976 0.000
L1.Vorarlberg 0.071079 0.025915 2.743 0.006
L1.Wien 0.079032 0.047667 1.658 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174048 0.047129 3.693 0.000
L1.Burgenland -0.005526 0.031851 -0.174 0.862
L1.Kärnten -0.061185 0.016966 -3.606 0.000
L1.Niederösterreich -0.083562 0.066648 -1.254 0.210
L1.Oberösterreich 0.193003 0.063906 3.020 0.003
L1.Salzburg 0.057687 0.033900 1.702 0.089
L1.Steiermark 0.229692 0.044422 5.171 0.000
L1.Tirol 0.494994 0.036024 13.741 0.000
L1.Vorarlberg 0.049933 0.030981 1.612 0.107
L1.Wien -0.047073 0.056985 -0.826 0.409
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160317 0.054073 2.965 0.003
L1.Burgenland -0.011344 0.036544 -0.310 0.756
L1.Kärnten 0.065891 0.019466 3.385 0.001
L1.Niederösterreich 0.200325 0.076469 2.620 0.009
L1.Oberösterreich -0.060803 0.073322 -0.829 0.407
L1.Salzburg 0.217252 0.038895 5.586 0.000
L1.Steiermark 0.113591 0.050968 2.229 0.026
L1.Tirol 0.077759 0.041332 1.881 0.060
L1.Vorarlberg 0.124593 0.035546 3.505 0.000
L1.Wien 0.114356 0.065382 1.749 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351969 0.031527 11.164 0.000
L1.Burgenland 0.006030 0.021306 0.283 0.777
L1.Kärnten -0.023628 0.011350 -2.082 0.037
L1.Niederösterreich 0.224325 0.044584 5.031 0.000
L1.Oberösterreich 0.174253 0.042749 4.076 0.000
L1.Salzburg 0.048233 0.022677 2.127 0.033
L1.Steiermark -0.016547 0.029716 -0.557 0.578
L1.Tirol 0.109602 0.024098 4.548 0.000
L1.Vorarlberg 0.073857 0.020724 3.564 0.000
L1.Wien 0.053040 0.038120 1.391 0.164
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041461 0.152238 0.189651 0.158493 0.124361 0.114627 0.065793 0.226418
Kärnten 0.041461 1.000000 -0.002605 0.129790 0.042135 0.096142 0.429565 -0.053014 0.101150
Niederösterreich 0.152238 -0.002605 1.000000 0.337638 0.155452 0.300727 0.111562 0.184343 0.328241
Oberösterreich 0.189651 0.129790 0.337638 1.000000 0.233066 0.333014 0.173263 0.172840 0.263439
Salzburg 0.158493 0.042135 0.155452 0.233066 1.000000 0.146986 0.129154 0.149459 0.134947
Steiermark 0.124361 0.096142 0.300727 0.333014 0.146986 1.000000 0.153978 0.141111 0.079446
Tirol 0.114627 0.429565 0.111562 0.173263 0.129154 0.153978 1.000000 0.115445 0.155366
Vorarlberg 0.065793 -0.053014 0.184343 0.172840 0.149459 0.141111 0.115445 1.000000 0.007626
Wien 0.226418 0.101150 0.328241 0.263439 0.134947 0.079446 0.155366 0.007626 1.000000